<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>异步请求测试</title>
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- 引入Vue -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
</head>

<body>
    <h1>异步请求测试</h1>
    <div>
        {{info}}

        <input type="button" value="异步请求" @click="f()">
    </div>
    <script>
        let v = new Vue({
            el: "body>div",
            data: {
                info: "异步测试"
            },
            methods: {
                f() {
                    // 发出异步请求
                    axios.get("/helloAxios").then(function (response) {
                        // response是响应对象,response.data得到服务器的数据
                        alert(response.data);
                        v.info = response.data;
                    });
                }
            }
        })
    </script>
</body>

</html>